package com.bestcem.xm.deliver.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bestcem.xm.component.mybatis.service.impl.XmServiceImpl;
import com.bestcem.xm.deliver.controller.v2.param.GetDeliverextparamsPageParam;
import com.bestcem.xm.deliver.controller.v2.vo.DeliverDeliverExtPageVo;
import com.bestcem.xm.deliver.entity.DeliverDeliverExtParams;
import com.bestcem.xm.deliver.mapper.DeliverDeliverExtParamsMapper;
import com.bestcem.xm.deliver.service.DeliverDeliverExtParamsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.List;

/**
 * @author been
 * @description 针对表【ds_deliver_deliverextparams】的数据库操作Service实现
 * @createDate 2022-11-07 13:49:46
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DeliverDeliverExtParamsServiceImpl extends XmServiceImpl<DeliverDeliverExtParamsMapper, DeliverDeliverExtParams>
        implements DeliverDeliverExtParamsService {

    @Override
    public DeliverDeliverExtParams getOneDeliverextparams(String id) {
        return baseMapper.selectById(id);
    }

    @Override
    public List<DeliverDeliverExtParams> getDeliverextparamsList(GetDeliverextparamsPageParam param) {
        LambdaQueryWrapper<DeliverDeliverExtParams> defaultWrapper = Wrappers.lambdaQuery();
        if (!param.getDeliverId().isEmpty()) {
            defaultWrapper.eq(DeliverDeliverExtParams::getDeliverId, param.getDeliverId());
        }
        if (ObjectUtil.isNotEmpty(param.getSearch())) {

        }
        if (ObjectUtil.isNotEmpty(param.getDeliverExtparamType())) {
            defaultWrapper.eq(DeliverDeliverExtParams::getDeliverExtparamType, param.getDeliverExtparamType());
        }
        if (ObjectUtil.isNotEmpty(param.getExtparamType())) {
            defaultWrapper.eq(DeliverDeliverExtParams::getExtparamType, param.getExtparamType());
        }
        if (ObjectUtil.isNotEmpty(param.getSource())) {
            defaultWrapper.eq(DeliverDeliverExtParams::getSource, param.getSource());
        }
        if (ObjectUtil.isNotEmpty(param.getStatus())) {
            defaultWrapper.eq(DeliverDeliverExtParams::getStatus, param.getStatus());
        }
        return baseMapper.selectList(defaultWrapper);
    }

    @Override
    public DeliverDeliverExtPageVo getCustomlinks(@ApiIgnore Page<DeliverDeliverExtParams> page, GetDeliverextparamsPageParam param) {
        DeliverDeliverExtPageVo pageVo = new DeliverDeliverExtPageVo();
        pageVo.setPage(page.getCurrent());

        LambdaQueryWrapper<DeliverDeliverExtParams> defaultWrapper = Wrappers.lambdaQuery();
        if (ObjectUtil.isNotEmpty(param.getDeliverId())) {
            defaultWrapper.eq(DeliverDeliverExtParams::getDeliverId, param.getDeliverId());
        }
        if (ObjectUtil.isNotEmpty(param.getSearch())) {

        }
        if (ObjectUtil.isNotEmpty(param.getDeliverExtparamType())) {
            defaultWrapper.eq(DeliverDeliverExtParams::getDeliverExtparamType, param.getDeliverExtparamType());
        }
        if (ObjectUtil.isNotEmpty(param.getExtparamType())) {
            defaultWrapper.eq(DeliverDeliverExtParams::getExtparamType, param.getExtparamType());
        }
        if (ObjectUtil.isNotEmpty(param.getSource())) {
            defaultWrapper.eq(DeliverDeliverExtParams::getSource, param.getSource());
        }
        if (ObjectUtil.isNotEmpty(param.getStatus())) {
            defaultWrapper.eq(DeliverDeliverExtParams::getStatus, param.getStatus());
        }
        Page<DeliverDeliverExtParams> deliverDeliverExtParamsPage = baseMapper.selectPage(page, defaultWrapper);
        //判空
        List<DeliverDeliverExtParams> deliverDeliverExtParamsList = deliverDeliverExtParamsPage.getRecords();
        if (CollUtil.isEmpty(deliverDeliverExtParamsList)) {
            pageVo.setTotalCount(0);
            pageVo.setRows(new ArrayList<>());
            return pageVo;
        }
        //组装
        pageVo.setRows(deliverDeliverExtParamsList);
        pageVo.setTotalCount(deliverDeliverExtParamsPage.getTotal());
        return pageVo;
    }
}




